package com.zretc.service.impl;

import com.zretc.dao.AddressInfoMapper;
import com.zretc.dao.AddressMapper;
import com.zretc.entity.Address;
import com.zretc.entity.AddressInfo;
import com.zretc.service.AddressInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: bLUeSuMMerDreamer
 * @createTime: 2020-07-25 04:13
 */
@Service
public class AddressInfoServiceImpl implements AddressInfoService {
    @Autowired
    private AddressInfoMapper addressInfoMapper;
    @Autowired
    private AddressMapper addressMapper;

    /**
     * 添加地址簿信息
     *
     * @param addressInfo@author: bLUeSuMMerDreamer
     * @date: 2020/7/25 4:11
     * @return: java.lang.Boolean
     */
    @Override
    @Transactional
    public Boolean addAddressInfo(AddressInfo addressInfo) {
        if (addressMapper.insertAddress(addressInfo.getAddress()) == 1) {
            return addressInfoMapper.insertAddressInfo(addressInfo) == 1;
        } else {
            return false;
        }
    }

    /**
     * 根据Id获取地址簿信息
     *
     * @param: addressInfoId
     * @author: bLUeSuMMerDreamer
     * @date: 2020/7/25 20:54
     * @return: com.zretc.entity.AddressInfo
     */
    @Override
    public AddressInfo getAddressInfoById(String addressInfoId) {
        Map<String, Object> params = new HashMap<>();
        params.put("addressInfoId", addressInfoId);
        AddressInfo addressInfo = addressInfoMapper.findAddressInfoByParams(params).get(0);
        return addressInfo;
    }

}
